package com.example.wisdomclassroomapi.config;

import com.example.wisdomclassroomapi.common.util.*;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@Configuration
public class UtilConfig {
    @Resource
    private RestTemplate restTemplate;

    @Bean
    public IdentificationUtil identificationUtil() {
        return new IdentificationUtil();
    }

    @Bean
    public JsonUtil jsonUtil() {
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        return new JsonUtil(objectMapper);
    }

    @Bean
    public RestUtil restUtil() {
        return new RestUtil(restTemplate, jsonUtil());
    }

    @Bean
    public ImageVerificationCodeUtil imageVerificationCodeUtil() {
        return new ImageVerificationCodeUtil();
    }

    @Bean
    public MessageDigestUtil messageDigestUtil() {
        return new MessageDigestUtil();
    }
}
